package com.sample.generator.config.impl;

import java.io.File;
import java.io.IOException;
import java.util.Properties;

public class FileSystemTemplateConfig extends AbstractTemplateConfig {

	public FileSystemTemplateConfig(String name) {

		super(name);
	}

	public FileSystemTemplateConfig(String name, String encoding) {

		super(name, encoding);
	}

	@Override
	public String getName() {

		File f = getTemplateFile();
		return f.getName();
	}

	public String getResourceLoaderPath() throws IOException {

		File f = getTemplateFile().getCanonicalFile();
		return f.getParent();
	}

	private File getTemplateFile() {

		String path = super.getName();
		return new File(path);
	}

	@Override
	public Properties getProperties() throws IOException {

		Properties props = super.getProperties();
		String resourceLoaderPath = getResourceLoaderPath();
		props.setProperty("file.resource.loader.path", resourceLoaderPath);
		return props;
	}
}
